<template>
  <m-container>
    <in-work-scan @click="handleClick" :palletCode="palletCode" />
    <m-cell-group class="box" v-for="(item, index) in list" :key="index" weight="label">
      <m-cell>
        <view class="row"> <text class="title">零件图号</text> TA71-2810010AB </view>
        <view class="row"> <text class="title">包装数量</text> 1 </view>
        <in-work-code broder statusTxt="" :size="88" :modal="item" />
      </m-cell>
    </m-cell-group>
    <m-empty tip="还没有开始扫码托盘码哦！" />
  </m-container>
</template>

<script>
const barcodeModel = uni.requireNativePlugin('iData-BarcodePlugin-BarcodeModule')
const globalEvent = uni.requireNativePlugin('globalEvent')
export default {
  data() {
    return {
      palletCode: '',
      list: [],
    }
  },
  onUnload() {
    barcodeModel.closeScan()
  },
  onShow() {
    barcodeModel.initScan()
  },
  onLoad() {
    globalEvent.addEventListener('iDataBarcodeEvent', async ({ barcode }) => {
      if (this.$Router.currentRoute.name !== 'InventoryInfo') {
        return
      }

      if (barcode.startsWith('WMS-P-')) {
        this.palletCode = barcode
      } else {
        this.list.push({ barcode })
      }
    })
  },
  methods: {
    handleClick() {
      barcodeModel.scanStart(() => {
        console.log(7)
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.row {
  display: flex;
  font-size: 30rpx;
  margin-bottom: 17rpx;
  .title {
    color: #748da7;
    font-size: 26rpx;
    width: 180rpx;
  }
}
</style>
